package com.yxjx.duoxue.network;

import com.yxjx.duoxue.Yx;
import com.yxjx.duoxue.dao.Dao;
import com.yxjx.duoxue.datamodel.ResponseObject;
import com.yxjx.duoxue.my.UserRegActivity;
import com.yxjx.duoxue.payment.ClientUserKidsDTS;
import com.yxjx.duoxue.utils.Utils;

import android.content.Context;

/**
 * 登录成功后的返回的value，用于记录重要的登录相关的信息。
 * @author mengmengchen
 *
 */
public class UserLoginResponse extends ResponseObject {

	public UserLoginResponse(int code, String msg) {
		super(code, msg);
	}

	public UserLoginResponse() {
		this(-1, "");
	}
	
	private String uId;
	private String sid;
	private String sessionKey;
	
	private String phoneNumber;
	private String userPassword;
	
	private ClientUserKidsDTS kidInfo;
	
	public String getSid() {
		return sid;
	}
	public void setSid(String sid) {
		this.sid = sid;
	}
	public String getSessionKey() {
		return sessionKey;
	}
	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	public boolean isOk() {
		return getCode() == MsgCode.SUCCESS;
	}
	public String getuId() {
		return uId;
	}
	public void setuId(String uId) {
		this.uId = uId;
	}
	public String getUserPassword() {
		return userPassword;
	}
	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}
	
	public static UserLoginResponse getInstance(Context context) {
		if (Utils.isLogin(context)) {
			UserLoginResponse rsp = new UserLoginResponse();
			rsp.setPhoneNumber(Utils.getValueFromSharedPreference(context, Yx.KEY_PHONE_NUM));
			rsp.setUserPassword(Utils.getValueFromSharedPreference(context, Yx.KEY_PHONE_PASSWORD));
			rsp.setSessionKey(Utils.getValueFromSharedPreference(context, Yx.KEY_SESSION_KEY));
			rsp.setSid(Utils.getValueFromSharedPreference(context, Yx.KEY_SID));
			rsp.setuId(Utils.getValueFromSharedPreference(context, Yx.KEY_UID));
			rsp.setKidInfo(Dao.getUserKidInfo(context));
			return rsp;
		}
		return null;
	}
	
	public static String getPhoneNum(Context context) {
		return Utils.getValueFromSharedPreference(context, Yx.KEY_PHONE_NUM);
	}

	public ClientUserKidsDTS getKidInfo() {
		return kidInfo;
	}

	public void setKidInfo(ClientUserKidsDTS kidInfo) {
		this.kidInfo = kidInfo;
	}
	
}
